﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.Design.WebControls;
using System.ComponentModel;
using System.Web.UI.Design;
using System.ComponentModel.Design;

namespace Ajaxna.Designers
{
    public class CustomTypeUIExampleDesigner : ControlDesigner
    {
        CustomTypeUIExample _myControl;
        DesignerVerbCollection _verbs;

        public CustomTypeUIExampleDesigner()
        {
            _verbs = new DesignerVerbCollection();
            _verbs.Add(new DesignerVerb("Scripts", new EventHandler(OnScripts)));
        }

        public override void Initialize(IComponent component)
        {
            base.Initialize(component);
            _myControl = component as CustomTypeUIExample;
        }

        protected void OnScripts(object sender, EventArgs e)
        {            
            ITypeDescriptorContext context = GetService(typeof(ITypeDescriptorContext)) as ITypeDescriptorContext;
            CollectionEditor editor = new CollectionEditor(typeof(List<AjaxnaScriptReference>));
            editor.EditValue(context, this.Component.Site, _myControl.Scripts);
        }

        public override System.ComponentModel.Design.DesignerVerbCollection Verbs
        {
            get
            {
                return _verbs;
            }
        }

        public override string GetDesignTimeHtml()
        {
            return CreatePlaceHolderDesignTimeHtml();
        }
    }
}
